import { defineStore } from 'pinia'
import {
  getCategory1,
  getCategory2,
  getCategory3,
} from '@/api/product/attr/index.ts'
import { categoryResponseData } from '@/api/product/attr/type.ts'
import { Category } from './type.ts'
let useStoreCategory = defineStore('useStoreCategory', {
  // 存储数据
  state: (): Category => {
    return {
      c1Arr: [],
      c1Id: '',
      c2Arr: [],
      c2Id: '',
      c3Arr: [],
      c3Id: '',
    }
  },
  // 异步|逻辑
  actions: {
    async getC1() {
      let res: categoryResponseData = await getCategory1()
      if (res.code == 200) {
        this.c1Arr = res.data
      }
    },
    async getC2() {
      let res: categoryResponseData = await getCategory2(this.c1Id)
      if (res.code == 200) {
        this.c2Arr = res.data
      }
    },
    async getC3() {
      let res: categoryResponseData = await getCategory3(this.c2Id)
      if (res.code == 200) {
        this.c3Arr = res.data
      }
    },
  },
  getters: {},
})
export default useStoreCategory
